package com.etmvc.core;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.MapListHandler;

import com.et.ar.ActiveRecordBase;
import com.et.ar.ConvertUtil;
import com.et.mvc.binding.DataBinders;

public class BaseModel extends ActiveRecordBase{
	static{
        ConvertUtil.register(new DateConverter(), Date.class);
        DataBinders.register(Date.class, new DateBinder());
        DataBinders.register(Integer.class, new IntegerBinder());
        setValidatorResource(ResourceBundle.getBundle("res"));
    }
	public static List<Map<String, Object>> queryForList(String sql,Object[] args){
		QueryRunner qr  =   new  QueryRunner();
        List results = new ArrayList();
		try {
			results = (List) qr.query(getConnectionProvider(BaseModel.class).getConnection(), sql, args, new  MapListHandler());
		} catch (SQLException e) {
			e.printStackTrace();
		}
        return results;
	}
}
